package cn.walnut.web.async;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

/**
 * @program: walnut-security
 * @Date: 2018/12/21 23:07
 * @Author: Walnut1992
 * @Description:
 */

public class QueueListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private MOckQueue mOckQueue;

    @Autowired
    private DefferedResultHolder defferedResultHolder;

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        while (true) {
            if(StringUtils.isNotBlank(mOckQueue.getCompeteOrder())) {
                String competeOrder = mOckQueue.getCompeteOrder();
                logger.info("返回订单处理结果为:" + competeOrder);
                defferedResultHolder.getMap().get(competeOrder).setResult("place order complete");
            }
        }
    }
}
